package springcloud.controller;


import com.atguigu.springcloud.entities.CommonResult;
import com.atguigu.springcloud.entities.Payment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springcloud.service.PaymentSerivce;

@RequestMapping(value ="/payment")
@RestController
public class PaymentController {
    @Autowired
    private PaymentSerivce paymentSerivce;

    @Value("${server.port}")
    private String serverPort;

    @RequestMapping(value ="/creat")
    public CommonResult creatPayment(Payment payment) {
        CommonResult commonResult = new CommonResult();
        int creat = paymentSerivce.creat(payment);
        //log.info("*********传入参数"+payment);
        if(creat>0){
            return new CommonResult(200,"插入数据库成功,serverPort: "+serverPort,creat);
        }else {
            return new CommonResult(444,"插入数据库成功,serverPort: "+serverPort,creat);
        }
    }

    @RequestMapping(value = "/get/{id}")
    public CommonResult get(@PathVariable("id") Long  id){
        Payment payment = paymentSerivce.getPaymentById(id);
        return new CommonResult(200,"查询成功:ServerPort:"+serverPort,payment);
    }

    @GetMapping("/lb")
    public String getPaymentLb(){
        return serverPort;
    }
}
